﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProxyWrapper;

public partial class _Default : Page
{
    public string _messagetype = "";
    public string _message = "";
  
    protected string ValidationSucessful = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Request.QueryString["0"]!=null)
            {
                _message = "Session expired. Login Again";
                _messagetype = "E";
            }
            if (Session["UserObject"] != null)
            {
                Response.Redirect("~/Services.aspx",false);
            }

        }
        catch (Exception ex)
        {
        }
    }

    protected void CreateAccount_click(object sender, EventArgs e)
    {
        Response.Redirect("Register.aspx");
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string Username = username.Text.Trim();
        string Password = password.Text.Trim();

        try
        {
            UserServiceWrapper loginService = new UserServiceWrapper();
            ProxyWrapper.UserProxy.UserDetails obj = loginService.ValidateLogin(Username, Password);
            if (obj.IsUserValidated && !string.IsNullOrWhiteSpace(obj.EmailId))
            {
                Session["UserObject"] = obj;
                Response.Redirect("~/Services.aspx",false);
            }
            else
            {
                ValidationSucessful = "FALSE";
               // showMessages.ClientIDMode = System.Web.UI.ClientIDMode.Static;
              //  ._message.showMessages.InnerHtml = "<div class='warning'><p> </p><li>"+ obj.LoginMessage +".</li> <p></p></div>";
                _messagetype = "E";
                _message =  obj.LoginMessage;

            }
        }
        catch (Exception ee)
        {

        }

    }

    public string GetMessage()
    {
        string warning = "<div class='warning'><p></p><li>{0}</li><p></p></div>";
        string result = "<div class='success'><p></p><li>{0}</li><p></p></div>";
        if (_messagetype == "E")
            return string.Format(warning, _message);
        else if (_messagetype == "S")
            return string.Format(result, _message);
        else
            return "";

    }
}